/**
 * Created by Chen on 2016/2/18.
 */
define(function(require, exports, module){

    var $ = require('jquery');
    require('bootstrap');
    require('bootstrap.select');
    require('jquery.layer');
    require('jquery.icheck');

    var List = require('../../util/list.js');


    exports.loadList = function(param){
        var list = new List();
        list.options = {
            template : "list-template",
            container : "list-data",
            url : $CONFIG.base_url + "/api/topic/choice/list",
            param : param
        };
        list.load(function(){
            $(".topic-details").on('click',function(){
                exports.loadList1({"id":$(this).attr("value") });
            })
        });
    };
    exports.loadList({'student.id':$CONFIG.uid});

    $(".btn-search-submit").click(function(){
        var $form = $("#search-form");

        var postData = $form.serialize();
        exports.loadList(postData);
    });

    //
    //$("#list-data").on("click",".choice-change",function(){
    //    var data = $.parseJSON($(this).attr("data"));
    //    layer.confirm('要取消选题吗？', {
    //        btn: ['确认','取消'], //按钮
    //        shade: false //不显示遮罩
    //    }, function(){
    //        var posting = $.post($CONFIG.base_url + "/api/topic/choice/change", data);
    //        posting.done(function(data){
    //            if (data == true) {
    //                layer.msg('取消成功', {
    //                    icon:9,
    //                    time:2000
    //                },function(){
    //                    window.location.href = $CONFIG.base_url + "/student/choice/manage";
    //                });
    //            }
    //            else{
    //                layer.msg('选题已确定无法更换，请联系管理员', {icon:9});
    //            }
    //        });
    //    }, function(){
    //    });
    //});

    $("#list-data").on("click",".choice-change",function(){
        var data = $.parseJSON($(this).attr("data"));
        layer.confirm('是否取消选题？', {
            btn: ['确定','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            var posting = $.post($CONFIG.base_url + "/api/topic/choice/change", data);
                posting.done(function(data){
                    if(data == true){
                        layer.msg('取消成功', {
                            icon:1,
                            time:1000
                        },function(){
                            window.location.href = $CONFIG.base_url + "/student/choice/manage";
                        });
                    }else{
                        layer.msg('选题已通过审核无法取消，请联系教务', {
                            icon:9
                        });
                    }
            });
        }, function(){
        });
    });

    //显示详情模板
    exports.loadList1 = function(param){
        var list = new List();
        list.options = {
            template : "list-template1",
            container : "list-data1",
            url : $CONFIG.base_url + "/api/topic/choice/details",
            param : param
        };
        list.load();
    };

});
